package com.csx.micrometer.demo.provider.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;

/**
 * @author cuisongxu
 * @date 2022/12/4 10:05
 */
@RestController
@RequestMapping("/provider")
public class DemoProviderController {

    @GetMapping("/getUsername")
    public String getUserName() {
        return "zhangsan";
    }

    /**
     * 测试随机性失败
     * @return
     */
    @GetMapping("/testRandomError")
    public String testRandomError() {
        Random random = new Random();
        int i = random.nextInt();
        if(i < 0.5) {
            throw new RuntimeException();
        }
        return "test feign random error";
    }

    @GetMapping("/testTimeout")
    public String testTimeout() {
        try {
            Thread.sleep(9999999);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "test timeout";
    }

}
